package com.film.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.film.domain.Film;
import com.film.domain.Review;
import com.film.domain.ReviewAndFilm;
import com.film.domain.User;
import com.film.service.FilmService;
import com.film.service.ReviewPriaseService;
import com.film.service.ReviewService;
import com.film.service.impl.FilmServiceImpl;
import com.film.service.impl.ReviewPriaseServiceImpl;
import com.film.service.impl.ReviewServiceImpl;
/**
 * 该控制类用来做单个电影的信息展示
 * @author 2119196781
 *
 */
@WebServlet("/selectOneFilm.do")
public class FilmOneController extends HttpServlet {
	private  FilmService filmService = new FilmServiceImpl();
	private  ReviewService reviewService = new ReviewServiceImpl();
	private  ReviewPriaseService  reviewPriaseService  = new ReviewPriaseServiceImpl();
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		//获取前台的传递的电影id
		String film_id = request.getParameter("filmId");
		//进行转型
		int filmid = Integer.parseInt(film_id);
		//查询所有的用户的评论
		List<Review> reviews = reviewService.selectAllReview(filmid);
		
		//调用FilmServiceImpl方法
		Film filmOne = filmService.FilmOneTypeAndDirectoe(filmid); 
		
		User user = (User)session.getAttribute("userLogin");
		if(user != null) {
			//根据用户的id和电影id查重
			Review reviewInfo = reviewService.selectReviewInfo(filmid,user.getuId());
			session.setAttribute("reviewInfo", reviewInfo);
		}
		
		//通过用户的id查询点赞过的评论id号
		if(user != null) {
			List<Integer> revIds = reviewPriaseService.selectUserReviewPriase(user.getuId());
			session.setAttribute("revIds", revIds);
		}
		ReviewAndFilm reviewAndFilm = reviewService.selectFilmReviewScore(filmid);
		session.setAttribute("filmOne", filmOne);
		session.setAttribute("reviews", reviews);
		session.setAttribute("reviewAndFilm", reviewAndFilm);
		response.sendRedirect("filmDetails.jsp");
	}
}
